package com.yc.bos.web.action;

import com.yc.bos.model.Decidedzone;
import com.yc.bos.service.IDecidedzoneService;
import com.yc.bos.web.action.base.BaseAction;
import com.gyf.crm.domain.Customer;
import com.gyf.crm.service.CustomerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.List;

public class DecidedzoneAction extends BaseAction<Decidedzone> {
    private String[] subareaId;//分区的id

    public void setSubareaId(String[] subareaId) {
        this.subareaId = subareaId;
    }

    @Autowired
    private IDecidedzoneService decidedzoneService;
    @Autowired
    private CustomerService customerService;

    @Override
    public String save() {
        System.out.println("参数:" + getModel());
        System.out.println("参数:" + getModel().getStaff());
        System.out.println("参数:" + StringUtils.join(subareaId, "，"));
        //调用service
        decidedzoneService.save(getModel(), subareaId);
        return SUCCESS;
    }

    @Override
    public String update() {
        return null;
    }

    @Override
    public String delete() throws IOException {
        return null;
    }

    @Override
    public String list() {
        return null;
    }

    public void pageQuery() throws IOException {
        pd.setCurrentPage(page);
        pd.setPageSize(rows);
        decidedzoneService.pageQuery(pd);
        responseJson(pd, new String[]{"currentPage", "pageSize", "detachedCriteria"});
    }
//-----------获取关连定区的客户信息====--------------------
    public  void findhasassociationCustomers() throws IOException {
        List<Customer> list=customerService.findhasassociationCustomers(getModel().getId());
        responseJson(list,new String[]{});
    }


//==============获取未关连定区的客户信息=======
    public  void findnoassociationCustomers() throws IOException {
        List<Customer> list=customerService.findnoassociationCustomers();
        responseJson(list,new String[]{});
    }


    //==================关连客户到定区===========================
    private Integer[] customerIds;

    public Integer[] getCustomerIds() {
        return customerIds;
    }

    public void setCustomerIds(Integer[] customerIds) {
        this.customerIds = customerIds;
    }

    public String assigncustomerstodecidedzone() {
        customerService.assignCustomersToDecidedZone(customerIds, getModel().getId());
        return SUCCESS;
    }
}
